# coding=utf-8
from scapy.all import *
from utils import pacp_util
from signal import signal, SIGINT

now_time = datetime.now().strftime("%Y%m%d%H%M%S")
filename = "../pcapng_files/netdataset-{0}.pcap".format(now_time)
o_open_file = PcapWriter(filename, append=True)

def callback(packet):
    packet.show()
    o_open_file.write(packet)
    pacp_util.pcaps_analysis(packet)

def signal_handler(sig, frame):
    print("捕获到中断信号，停止监听...")
    exit(0)


def stop():
    # 注册 SIGINT 信号的处理函数
    signal(SIGINT, signal_handler)

def start():
    dpkt_input = sniff(iface="Realtek 8821CE Wireless LAN 802.11ac PCI-E NIC", count=0, filter='tcp', prn=callback)
